import React, { createContext, useState, useContext } from "react";

// 定义上下文类型
interface ICollapseContext {
  collapsed: boolean;
  setCollapsed: (collapsed: boolean) => void;
}

// 创建上下文
export const CollapseContext = createContext<ICollapseContext>({
  collapsed: false,
  setCollapsed: () => {}
});

// 提供者
export const CollapseProvider: React.FC<{ children: React.ReactNode }> = ({
  children
}) => {
  const [collapsed, setCollapsed] = useState(false);
  return (
    <CollapseContext.Provider value={{ collapsed, setCollapsed }}>
      {children}
    </CollapseContext.Provider>
  );
};
/**
 * 自定义hook 控制menu的折叠
 * @returns
 */
export const useCollapse = () => useContext(CollapseContext);
